package com.atao.baokede.mapper;

import com.atao.baokede.pojo.ChargeOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChargeOrderMapper {
    // 添加用户余额支付订单
    @Insert("insert into charge_order(user_id, order_no, request_amount, status, created_time) values(#{userId}, #{orderNo}, #{requestAmount}, #{status}, now())")
    void insert(ChargeOrder chargeOrder);

    // 修改用户余额支付订单
    @Update("update charge_order set   status=#{status}, completed_time=now() where id=#{id}")
    void updateById(ChargeOrder chargeOrder);

    // 根据订单编号查询用户余额支付订单
    @Select("select * from charge_order where order_no = #{orderNo}")
    ChargeOrder selectByOrderNo(Long orderNo);

    // 查询当前用户余额支付订单
    @Select("select * from charge_order where user_id = #{userId}")
    List<ChargeOrder> findAllByUserId(Long userId);

    // 删除用户余额支付订单
    @Delete("delete from charge_order where order_no = #{orderNo}")
    void deleteById(Long orderNo);

    // 修改订单状态
    @Update("update charge_order set status = #{statusRefunded} where order_no = #{orderNo}")
    void updateStatus(Long orderNo, int statusRefunded);
}
